package com.ysy.tz.mfg.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.javafx.collections.ObservableListWrapper;
import com.ysy.tz.core.engine.ApplicationContext;
import com.ysy.tz.core.engine.DefaultKeyValuePair;
import com.ysy.tz.core.selfcomp.CustomerComboBox;
import com.ysy.tz.core.selfcomp.CustomerPagination;
import com.ysy.tz.core.selfcomp.KeyValueTableColumn;
import com.ysy.tz.core.utils.FormUtils;
import com.ysy.tz.core.utils.ModelUtils;
import com.ysy.tz.core.utils.SQLUtils;
import com.ysy.tz.core.utils.SessionUtils;
import com.ysy.tz.mfg.dao.CarcassOutWarehouseDao;
import com.ysy.tz.mfg.dao.GradingRuleDao;
import com.ysy.tz.mfg.entity.CarcassOutWarehouseEntity;
import com.ysy.tz.mfg.entity.GradingRuleEntity;
import com.ysy.tz.mfg.entity.UserEntity;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;

public class CarcassOutWarehouseListController implements Initializable {
    @FXML
    BorderPane queryForm;
    @FXML
    TableView outWarehouseTableView;
    @FXML
    CustomerPagination outWarehousePagination;
    @FXML
    CustomerComboBox levelCode;
    @FXML
    CustomerComboBox slaughterType;
    @FXML
    CustomerComboBox gender;
    @FXML
    CustomerComboBox workFlightsCode;
    @FXML
    KeyValueTableColumn tb_slaughterType;
    @FXML
    KeyValueTableColumn tb_gender;
    @FXML
    KeyValueTableColumn tb_workFlightsCode;
    @FXML
    KeyValueTableColumn tb_mjType;

    public CarcassOutWarehouseListController() {
    }

    public void initialize(URL url, ResourceBundle resourceBundle) {
        ArrayList<GradingRuleEntity> gradingRuleEntities = (ArrayList)SQLUtils.executeSQLWithReturn(GradingRuleDao.class, (gradingRuleDao) -> {
            try {
                return gradingRuleDao.searchGradingRuleList(ApplicationContext.enterpriseId);
            } catch (Exception var2) {
                var2.printStackTrace();
                return null;
            }
        });
        this.levelCode.setItems(new ObservableListWrapper(gradingRuleEntities));
        this.workFlightsCode.setItems(new ObservableListWrapper((ArrayList)SessionUtils.getAttribute(SessionUtils.FLIGHTS)));
        this.tb_workFlightsCode.setKeyValuePairs((ArrayList)SessionUtils.getAttribute(SessionUtils.FLIGHTS));
        ArrayList<DefaultKeyValuePair> slaughterTypes = new ArrayList();
        slaughterTypes.add(new DefaultKeyValuePair("B", "扒皮"));
        slaughterTypes.add(new DefaultKeyValuePair("T", "褪毛"));
        this.slaughterType.setItems(new ObservableListWrapper(slaughterTypes));
        this.tb_slaughterType.setKeyValuePairs(slaughterTypes);
        ArrayList<DefaultKeyValuePair> genders = new ArrayList();
        genders.add(new DefaultKeyValuePair("G", "公"));
        genders.add(new DefaultKeyValuePair("M", "母"));
        this.gender.setItems(new ObservableListWrapper(genders));
        this.tb_gender.setKeyValuePairs(genders);
        ArrayList<DefaultKeyValuePair> mjTypes = new ArrayList();
        mjTypes.add(new DefaultKeyValuePair("M", "毛腔"));
        mjTypes.add(new DefaultKeyValuePair("J", "净腔"));
        this.tb_mjType.setKeyValuePairs(mjTypes);
    }

    public void query(MouseEvent mouseEvent) {
        CarcassOutWarehouseEntity condition = null;

        try {
            condition = (CarcassOutWarehouseEntity)FormUtils.collectParams(this.queryForm, CarcassOutWarehouseEntity.class);
        } catch (Exception var4) {
            var4.printStackTrace();
        }

        condition.setPageNum(this.outWarehousePagination.getCurrentPageIndex() + 1);
        condition.setPageSize(this.outWarehousePagination.getPageSize());
        PageInfo<CarcassOutWarehouseEntity> userList = this.searchGradingDetailRecords(condition);
        ModelUtils.setTableViewValue(userList, this.outWarehouseTableView, this.outWarehousePagination);
    }

    public PageInfo<CarcassOutWarehouseEntity> searchGradingDetailRecords(CarcassOutWarehouseEntity condition) {
        return (PageInfo)SQLUtils.executeSQLWithReturn(CarcassOutWarehouseDao.class, (carcassoutWarehouseDao) -> {
            PageHelper.startPage(condition.getPageNum(), condition.getPageSize());
            UserEntity currentUser = (UserEntity)SessionUtils.getAttribute(SessionUtils.CURRENT_USER);
            condition.setEnterpriseId(currentUser.getEnterpriseId());

            try {
                List carcassoutWarehouseEntitys = carcassoutWarehouseDao.listForPage(condition);
                PageInfo<CarcassOutWarehouseEntity> result = new PageInfo(carcassoutWarehouseEntitys);
                return result;
            } catch (Exception var5) {
                var5.printStackTrace();
                return null;
            }
        });
    }

    public void reset(MouseEvent mouseEvent) {
        FormUtils.resetFrom(this.queryForm);
    }
}
